$('#registerBtn').click(function(){
  let username = $('#username').val();
  let pwd = $('#pwd').val();
  let confirm = $('#confirm').val();
  let code = $('#code').val();
  if(!username){
    alert("用户名不能为空");
  } else if(!pwd){
    alert("密码不能为空");
  }else if(pwd !== confirm){
    alert('两次密码输入的不一致');
  } else if(!code){
    alert('验证码不能为空');
  } else {
    $.ajax({
      type: 'POST',
      url: '/register',
      data: {username, pwd, code},
      xhrFields: {
        withCredentials: true
      },
      contentType: "application/x-www-form-urlencoded; charset=utf-8",
      success: function(response){
        if(response.status === '0'){
          var r = window.confirm("请重新登录");
          //alert(r);
          if(r){
            location.href = 'login.html';
          }
        }else if( response.status === '-1'){
          alert(response.message);
        }
      }
    })
  }
})
